package net.sky.oa.model;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

/**
 * 校区表
 * SysSchool. @author hond
 */
@Entity
@Table(name = "SYS_SCHOOL")//校区表
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class SysSchool implements java.io.Serializable {

	private static final long serialVersionUID = 5673991033245515351L;
	
	// Fields
 
	protected Long id;
	private String name;     //校区名称
	private String tel;      //前台电话
	private String principal;//负责人
	private String address;  //地址
	private Integer status;    //状态：1使用2禁用
	private Date createtime; //创建时间
	private SysEmployee user;  //创建人
	private Set<SysDept> depts = new HashSet<SysDept>(0);
	
	
	
	private String oldname;        //记录原名称
	
	// Constructors

	/** default constructor */
	public SysSchool() {
	}
	
	/**
	 * @param id
	 * @param name
	 */
	public SysSchool(Long id, String name) {
		super();
		this.id = id;
		this.name = name;
	}



	@Id
    @Column(name = "ID", unique = true, nullable = false)
	@SequenceGenerator(name="SQ_SYSSCHOOL_ID",sequenceName="SQ_SYSSCHOOL_ID",allocationSize=1)
	@GeneratedValue(strategy=GenerationType.SEQUENCE,generator="SQ_SYSSCHOOL_ID")
	public Long getId() {
        return id;
    }

    public void setId(Long id){
    	this.id = id;
    }

	/** minimal constructor */
	public SysSchool(Long id) {
		this.id = id;
	}
 
	@Column(name = "NAME", length = 30)
	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(name = "TEL", length = 40)
	public String getTel() {
		return this.tel;
	}

	public void setTel(String tel) {
		this.tel = tel;
	}
	
	@Column(name = "PRINCIPAL", length = 10)
	public String getPrincipal() {
		return this.principal;
	}

	public void setPrincipal(String principal) {
		this.principal = principal;
	}

	@Column(name = "ADDRESS", length = 60)
	public String getAddress() {
		return this.address;
	}

	public void setAddress(String address) {
		this.address = address;
	}
	
	@Column(name = "STATUS", length = 1)
	public Integer getStatus() {
		return this.status;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "CREATETIME", length = 7)
	public Date getCreatetime() {
		return this.createtime;
	}

	public void setCreatetime(Date createtime) {
		this.createtime = createtime;
	}
	
	//FetchType.EAGER 此方法作用除了更新对象外，还能把脱管对象和Session进行关联。
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "USER_ID")
	public SysEmployee getUser() {
		return this.user;
	}

	public void setUser(SysEmployee user) {
		this.user = user;
	}

	@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	@JoinTable(name = "sys_school_dept",joinColumns = { @JoinColumn(name = "school_id", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "dept_id", nullable = false, updatable = false) })
	public Set<SysDept> getDepts() {
		return this.depts;
	}

	public void setDepts(Set<SysDept> depts) {
		this.depts = depts;
	}
	
	@Transient
	public String getOldname() {
		return oldname;
	}

	public void setOldname(String oldname) {
		this.oldname = oldname;
	}
	
}